package transtienda.Instrumentos.servlet;

import java.io.IOException;
import java.util.Collection;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import trastienda.excepcion.DAOExcepcion;
import trastienda.modelo.Instrumentos;
import trastienda.negocio.GestionInstrumentos;

/**
 * Servlet implementation class for Servlet: RolBuscarServlet
 * 
 */
@WebServlet("/InstrumentoBuscarServlet")
public class InstrumentoBuscarServlet extends javax.servlet.http.HttpServlet implements
		javax.servlet.Servlet {
	static final long serialVersionUID = 1L;

	/*
	 * (non-Java-doc)
	 * 
	 * @see javax.servlet.http.HttpServlet#HttpServlet()
	 */
	public InstrumentoBuscarServlet() {
		super();
	}

	/*
	 * (non-Java-doc)
	 * 
	 * @see javax.servlet.http.HttpServlet#doGet(HttpServletRequest request,
	 * HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		this.doPost(request, response);
	}

	/*
	 * (non-Java-doc)
	 * 
	 * @see javax.servlet.http.HttpServlet#doPost(HttpServletRequest request,
	 * HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		
		System.out.println("Dentro de doPost del servlet InstrumentoBuscarSerlvet");
		String a = request.getParameter("tipo");
		String b= request.getParameter("marca");
		String c = request.getParameter("modelo");
		String d = request.getParameter("cantidad");
		int k = Integer.parseInt(d);
		String f = request.getParameter("caracteristicas");
		String l = request.getParameter ("precio");
		double x = Double.parseDouble(l);
		int m=4;
		
		
		
		GestionInstrumentos negocio = new GestionInstrumentos();
		try {
			// Guardar en el ambiente de request
			negocio.insertar(a,b,c,k,f,x, m);
			RequestDispatcher rd = request
			.getRequestDispatcher("rolBuscar.jsp");
			rd.forward(request, response);

		} catch (DAOExcepcion e) {
			System.out.println(e.getMessage());
			RequestDispatcher rd = request.getRequestDispatcher("error.jsp");
			rd.forward(request, response);
		}

	}
}
